package leetcode.code0807;

public class Solution extends Solution807 {

	@Override
	public int maxIncreaseKeepingSkyline(int[][] grid) {
		int rowLen = grid.length;// 行数
		int colLen = grid[0].length;// 列数
		int[] rowMax = new int[rowLen];// 行最大记录
		int[] colMax = new int[colLen];// 列最大记录
		for (int i = 0; i < rowLen; i++) {
			int rMax = 0;
			for (int j = 0; j < colLen; j++) {
				int num = grid[i][j];
				rMax = Math.max(rMax, num);
				colMax[j] = Math.max(colMax[j], num);
			}
			rowMax[i] = rMax;// i行最大
		}
		int ans = 0;
		for (int i = 0; i < rowLen; i++) {
			for (int j = 0; j < colLen; j++) {
				ans += Math.min(rowMax[i], colMax[j]) - grid[i][j];// 行列最大值中最小的 - 当前的高度
			}
		}
		return ans;
	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();

	}

}
